//
//  MenuScene.m
//  jumpingfrog
//
//  Created by Tri Vo on 8/16/13.
//  Copyright 2013 Tri Vo. All rights reserved.
//

#import "MenuScene.h"
#import "GeneralDef.h"
#import "GameController.h"
#import "AboutScene.h"
#import "SettingsScene.h"
#import "ChooseLevelScene.h"
#import "GamePlayScene.h"
#import "GuideScene.h"
#import "SceneManager.h"


@implementation MenuScene

+ (CCScene *) scene {
    CCScene *scene = [CCScene node];
    
    MenuScene *layer = [MenuScene node];
    
    [scene addChild:layer];
    
    return scene;
}

- (id)init {
    if (self = [super init]) {
        [self initScreen];
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

- (void)onExit {
    [super onExit];
}

#pragma mark - Scene Methods

- (void) initScreen {
    CGSize winSize = [GameController getWinSize];
    CCSprite *background = [CCSprite spriteWithFile:IMG_BACKGROUND];
    [background setAnchorPoint:CGPointZero];
    [background setPosition:CGPointZero];
    [self addChild:background];
    
    // Game title
    CCLabelTTF *pLblTitle = [CCLabelTTF labelWithString:@"Jumping Frog" fontName:FONT_TITLE fontSize:28];
    [pLblTitle setPosition:CGPointMake(winSize.width/2, winSize.height/2 + 125)];
    [self addChild:pLblTitle];
    
    // Frog
    CCSprite *pFrog = [CCSprite spriteWithFile:IMG_FROG];
    [pFrog setScale:0.2f];
    [pFrog setPosition:CGPointMake(winSize.width - 100, winSize.height - 175)];
    [self addChild:pFrog];
    
    // Lily pad 1
    CCSprite *pLipad1 = [CCSprite spriteWithFile:IMG_TITLE_LILYPAD_1];
    [pLipad1 setScale:0.15f];
    [pLipad1 setPosition:ccp(winSize.width/2 - 150, winSize.height/2 + 70)];
    [self addChild:pLipad1];
    
    // Lily pad 2
    CCSprite *pLipad2 = [CCSprite spriteWithFile:IMG_TITLE_LILYPAD_2];
    [pLipad2 setScale:0.15f];
    [pLipad2 setPosition:ccp(winSize.width/2 - 100, winSize.height/2)];
    [self addChild:pLipad2];
    
    // Lily pad 3
    CCSprite *pLipad3 = [CCSprite spriteWithFile:IMG_TITLE_LILYPAD_3];
    [pLipad3 setScale:0.15f];
    [pLipad3 setPosition:ccp(winSize.width/2 - 150, winSize.height/2 - 70)];
    [self addChild:pLipad3];
    
    // Menu
    CCMenuItemFont *pBtnNewGame = [CCMenuItemFont itemWithString:STR_PLAY target:self selector:@selector(menuNewGame_Clicked)];
    CCMenuItemFont *pBtnGuide = [CCMenuItemFont itemWithString:STR_GUIDE target:self selector:@selector(menuGuide_Clicked)];
    CCMenuItemFont *pBtnSettings = [CCMenuItemFont itemWithString:STR_SETTINGS target:self selector:@selector(menuSettings_Clicked)];
    CCMenuItemFont *pBtnAbout = [CCMenuItemFont itemWithString:STR_ABOUT target:self selector:@selector(menuAbout_Clicked)];
    
    CCMenu *pMenu = [CCMenu menuWithItems:pBtnNewGame, pBtnGuide, pBtnSettings, pBtnAbout, nil];
    [pMenu setAnchorPoint:CGPointZero];
    [pMenu alignItemsVerticallyWithPadding:10];
    [pMenu setPosition:ccp(winSize.width/2, winSize.height/2)];
    [self addChild:pMenu];
}

#pragma mark - Scene Actions

- (void) menuNewGame_Clicked {
    [[SceneManager getInstance] goPlay];
}

- (void) menuGuide_Clicked {
    [[SceneManager getInstance] goGuide];
}

- (void) menuSettings_Clicked {
    [[SceneManager getInstance] goSettings];
}

- (void) menuAbout_Clicked {
    [[SceneManager getInstance] goAbout];
}

@end
